package org.abettor.myinj.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class I18n
{
	private String currentLang;
	private Properties prop;

	/**
	 * 以当前语言设置构造国际化语言对象
	 *
	 */
	public I18n()
	{
		currentLang = Configuration.getInstance().getProperty("Language");
		if(currentLang == null)
		{
			currentLang = "en_US";
		}

		File file = new File("i18n/" + currentLang + ".lang.properties");
		try
		{
			InputStream is = new FileInputStream(file);
			prop = new Properties();
			prop.load(is);
			is.close();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * 以特定语言设置构造国际化语言对象
	 *
	 */
	public I18n(String lang)
	{
		if(lang == null)
		{
			lang = "en_US";
		}

		File file = new File("i18n/" + lang + ".lang");
		try
		{
			InputStream is = new FileInputStream(file);
			prop = new Properties();
			prop.load(is);
			is.close();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	public String getString(String key)
	{
		return prop.getProperty(key);
	}
}
